home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / utils / kwikcopy / kwikcopy2.5.src < prev    next >
Text File  |  1980-01-03  |  47KB  |  2,428 lines

  1.  
  2. * Kwikcopy 2.5 - (c) Phil Ruston 27/6/94.
  3.  
  4.     section kwikcopy,code
  5.  
  6. ********
  7. * Init *
  8. ********
  9.  
  10.     movem.l d0-d7/a0-a6,-(a7)
  11.     
  12.     move.l $4,a6
  13.     jsr -$84(a6)    ;Forbid Multitask
  14.  
  15.     Move.l $4,a6
  16.     move.l #gfxlib.txt,a1
  17.     moveq #0,d0
  18.     jsr -$228(a6)
  19.     move.l d0,a3
  20.  
  21.     move.l #vars,a2
  22.     move.l $26(a3),orig_copper(a2)
  23.  
  24.     Move.l $4,a6
  25.     move.l d0,a1
  26.     moveq #0,d0
  27.     jsr -$19e(a6)
  28.     
  29.     move.w #$4000,$dff09a
  30.  
  31.     move.l #$dff000,a0
  32.     move.l #$bfd000,a1
  33.     move.l #vars,a2
  34.     move.w $1c(a0),orig_inten(a2)
  35.     move.w $1e(a0),orig_intreq(a2)
  36.     move.w $10(a0),orig_adkcon(a2)
  37.     move.w $2(a0),orig_dmacon(a2)
  38.     move.l $68,orig_lev2(a2)
  39.     move.l $6c,orig_lev3(a2)
  40.     move.b $100(a1),orig_bfd100(a2)
  41.     move.b $1001(a1),orig_bfe001(a2)
  42.     move.b $1f01(a1),orig_cr1(a2)
  43.     move.b #$10,$1f01(a1)
  44.     move.b $1601(a1),orig_tl1(a2)
  45.     move.b $1701(a1),orig_th1(a2)
  46.     move.b $f00(a1),orig_cr2(a2)
  47.     move.b #$10,$f00(a1)
  48.     move.b $600(a1),orig_tl2(a2)
  49.     move.b $700(a1),orig_th2(a2)
  50.     move.l $0,orig_zero(a2)
  51.     clr.l $0
  52.         
  53.     move.w #$7fff,$9a(a0)
  54.     move.w #$8400,$96(a0)
  55.     move.l #trap,$80
  56.     trap #0
  57. wait    bra wait
  58.  
  59. trap    move.l USP,a6
  60.     move.l a6,orig_usp(a2)
  61.     move.l a7,orig_a7(a2)
  62.     move.l #stack2,a6
  63.     move.l a6,USP
  64.     move.l #stack3,a7
  65.     eori.w #$2000,SR
  66.  
  67.     moveq #0,d7    ;Set up screen from character map.
  68.     move.l #charmap,a6
  69. nxt_line    moveq #0,d6    
  70.     bsr display_sentence4
  71.     addq.w #1,d7
  72.     cmpi.w #22,d7
  73.     bne.s nxt_line
  74.  
  75.     move.l #screen,d0
  76.     move.l #copper2,a1
  77.     addq.l #2,d0
  78.     move.w d0,$a(a1)
  79.     swap d0
  80.     move.w d0,$6(a1)
  81.     swap d0
  82.     add.l #44,d0
  83.     move.w d0,$12(a1)
  84.     swap d0
  85.     move.w d0,$e(a1)
  86.     swap d0
  87.     add.l #44,d0
  88.     move.w d0,$1a(a1)
  89.     swap d0
  90.     move.w d0,$16(a1)
  91.     swap d0
  92.     add.l #44,d0
  93.     move.w d0,$22(a1)
  94.     swap d0
  95.     move.w d0,$1e(a1)
  96.  
  97.     move.l #pointersprite,d0
  98.     move.w d0,$4e(a1)
  99.     swap d0
  100.     move.w d0,$4a(a1)
  101.  
  102.     move.l #trackstartsprite,d0
  103.     move.w d0,$5e(a1)
  104.     swap d0
  105.     move.w d0,$5a(a1)
  106.  
  107.     move.l #trackendsprite,d0
  108.     move.w d0,$6e(a1)
  109.     swap d0
  110.     move.w d0,$6a(a1)
  111.  
  112.     move.l #vars,a2
  113.     move.b #$80,keypressed(a2)
  114.     bsr go_default
  115.     bsr show_settings
  116.  
  117.     move.l #$bfd000,a1
  118.     move.b #$ff,$100(a1)
  119.     move.b #$87,$100(a1)
  120.     bsr shortwait
  121.     move.b #$ff,$100(a1)
  122.     bsr shortwait
  123.  
  124.     move.l #copper1,$80(a0)
  125.     move.l #irq,$6c
  126.     move.l #keyirq,$68
  127.     move.w #$c028,$9a(a0)
  128.  
  129.     move.b #$7f,$100(a1)    ;is df1: connected?
  130.     bclr #4,$100(a1)        
  131.     move.w #500,d7
  132.     bsr cia_wait
  133.     move.b #$ff,$100(a1)        
  134.     bclr #4,$100(a1)
  135.     moveq #$1f,d7
  136.     moveq #0,d0
  137. df1idloop    lsl.l #1,d0
  138.     bclr #4,$100(a1)
  139.     bsr vshrtwait
  140.     btst #5,$1001(a1)
  141.     beq.s nxtbit
  142.     ori.w #1,d0
  143. nxtbit    bset #4,$100(a1)
  144.     dbf d7,df1idloop
  145.     not.l d0
  146.     cmpi.l #-1,d0
  147.     beq.s df1_avail
  148.     move.l #nodf1,a6
  149.     bsr showmessage
  150.     bsr init_error_sound
  151.     move.w #2000,d7
  152.     bsr cia_wait
  153.     bra rs_df1
  154.  
  155. df1_avail    move.l #welcome,a6
  156.     bsr showmessage
  157.     bsr init_ok_sound
  158.     bsr shortwait
  159.     bsr reset_heads
  160.     move.w d4,orig_df0(a2)
  161.     move.w d5,orig_df1(a2)
  162.     move.b #$ff,$100(a1)
  163.     move.b #$87,$100(a1)
  164.     bsr vshrtwait
  165.     move.b #$ff,$100(a1)
  166.  
  167.  
  168. *************
  169. * Main loop *
  170. *************
  171.  
  172. wait_irq    move.l #$dff000,a0
  173.     move.l #$bfd000,a1
  174.     move.l #vars,a2
  175.     tst.w irq_occured(a2)
  176.     beq.s wait_irq
  177.     bsr adjust_range
  178.     clr.w irq_occured(a2)
  179.     move.w clicked_box(a2),d0
  180.     beq.s wait_irq
  181.  
  182.     clr.w clicked_box(a2)
  183.     clr.w dont_check(a2)
  184.     cmpi.w #$a,d0
  185.     beq return_to_dos
  186.     cmpi.w #$b,d0
  187.     bne.s no_namef
  188.     bsr fetch_name
  189.     bra ncheckd1
  190.  
  191. no_namef    cmpi.w #4,d0
  192.     bhi altersettings
  193.     bne.s notformat
  194.     bsr format_disk
  195.     cmpi.w #$2,check_mode(a2)
  196.     bne.s notformat
  197.     tst.w dont_check(a2)
  198.     bne ncheckd1
  199.     bsr check_disk
  200.     bra ncheckd1
  201.  
  202. notformat    cmpi.w #1,d0
  203.     bne.s ncopyd1
  204.     bsr copy_disk
  205.     cmpi.w #$2,check_mode(a2)
  206.     bne.s ncopyd1
  207.     tst.w dont_check(a2)
  208.     bne ncheckd1
  209.     bsr check_disk
  210.     bra ncheckd1
  211.  
  212. ncopyd1    cmpi.w #2,d0
  213.     bne.s ncheckd1
  214.     bsr check_disk
  215.  
  216. ncheckd1    clr.w irq_occured(a2)
  217.     clr.w clicked_box(a2)
  218.     bra wait_irq
  219.  
  220. ******************************************************************************
  221.  
  222. Return_to_DOS
  223.  
  224.     move.w #$7fff,$9a(a0)
  225.     move.l #goodbye,a6
  226.     bsr showmessage
  227.  
  228.     bsr reset_heads        ;put heads back to original
  229.     move.b #$ff,$100(a1)    ;positions.
  230.     bsr vshrtwait
  231.     move.b #$f7,$100(a1)
  232.     bclr #1,$100(a1)
  233. rslpdf0    subq.w #1,orig_df0(a2)
  234.     bmi.s rs_df0
  235.     bsr step_pulse
  236.     bra.s rslpdf0
  237.  
  238. rs_df0    bsr shortwait
  239.     move.b #$ff,$100(a1)
  240.     bsr vshrtwait
  241.     move.b #$ef,$100(a1)
  242.     bclr #1,$100(a1)
  243. rslpdf1    subq.w #1,orig_df1(a2)
  244.     bmi.s rs_df1
  245.     bsr step_pulse
  246.     bra.s rslpdf1
  247.  
  248. rs_df1    move.b #$ff,$100(a1)        ;reset drive hardware
  249.     bsr shortwait
  250.     move.b orig_bfd100(a2),$100(a1)
  251.     move.b orig_bfe001(a2),$1001(a1)
  252.  
  253.     move.l orig_lev2(a2),$68    ;reset int vectors
  254.     move.l orig_lev3(a2),$6c
  255.  
  256.     move.b orig_tl1(a2),$1601(a1)    ;reset cia timers
  257.     move.b orig_th1(a2),$1701(a1)
  258.     move.b orig_cr1(a2),$1f01(a1)
  259.     move.b orig_tl2(a2),$600(a1)
  260.     move.b orig_th2(a2),$700(a1)
  261.     move.b orig_cr2(a2),$f00(a1)
  262.  
  263.     move.l #trap2,$80
  264.     trap #0
  265. wait2    bra wait2
  266.  
  267. trap2    move.l orig_usp(a2),a6    ;reset stack pointers
  268.     move.l a6,USP
  269.     move.l orig_a7(a2),a7
  270.     eori.w #$2000,SR
  271.  
  272.     move.l orig_zero(a2),$0
  273.  
  274.     move.w orig_adkcon(a2),d0
  275.     ori.w #$8000,d0
  276.     move.w #$7fff,$9e(a0)
  277.     move.w d0,$9e(a0)
  278.  
  279.     move.w orig_intreq(a2),d0    ;reset int req
  280.     ori.w #$8000,d0
  281.     move.w #$7fff,$9c(a0)
  282.     move.w d0,$9c(a0)
  283.  
  284.     move.w orig_dmacon(a2),d0    ;reset dma control
  285.     ori.w #$8000,d0
  286.     move.w #$7fff,$96(a0)
  287.     move.w d0,$96(a0)
  288.     
  289.     move.l orig_copper(a2),$dff080
  290.     clr.w $dff088
  291.  
  292.     move.w orig_inten(a2),d0    ;reset int enable
  293.     ori.w #$c000,d0
  294.     move.w #$7fff,$9a(a0)
  295.     move.w d0,$9a(a0)
  296.  
  297.     move.l $4,a6
  298.     jsr -$8a(a6)        ;Permit Multitask
  299.     movem.l (a7)+,d0-d7/a0-a6
  300.     clr.w d0
  301.     rts
  302.  
  303. ******************************************************************************
  304.  
  305. Fetch_name:
  306.     
  307.     bsr clear_track_status    
  308.     bsr reset_heads
  309.     
  310.     move.w destination(a2),d0
  311.     eori.w #1,d0
  312.     add.w #3,d0
  313.     move.b #$7f,$100(a1)
  314.     bclr d0,$100(a1)    
  315.     bsr wait_motor
  316.     moveq #40,d0
  317.     bsr moveheads
  318.     move.b #$40,track_bcd(a2)
  319.     cmpi.w #$10,disk_error(a2)
  320.     bne.s name_go
  321. dskgonnam    tst.w destination(a2)
  322.     bne nodisk0
  323.     bra nodisk1
  324.  
  325. name_go    move.w #1,side_sel(a2)
  326.     move.w #3,re_read(a2)
  327. rereadnam    cmpi.w #3,clicked_box(a2)
  328.     beq terminated
  329.     bsr read_mfm
  330.     tst.w disk_error(a2)
  331.     beq.s trkok_nam
  332.     subq.w #1,re_read(a2)
  333.     bne.s rereadnam
  334.     cmpi.w #$10,disk_error(a2)
  335.     beq dskgonnam
  336.  
  337. trkok_nam    bsr show_track_status
  338.     
  339.     move.l #mfm_buffer,a3
  340.     lea $18e0*2(a3),a5
  341.  
  342. fsync_nam    cmp.l a5,a3
  343.     bhi cant_find_name
  344.     cmpi.w #$4489,(a3)+
  345.     bne.s fsync_nam
  346.     cmpi.w #$4489,(a3)
  347.     beq.s sync_nam
  348.     subq.w #2,a3
  349.     
  350. sync_nam    lea $2(a3),a4
  351.     bsr decode_long
  352.     andi.w #$ff00,d5
  353.     beq.s gsec0_nam
  354.     add.w #$430,a3
  355.     bra fsync_nam
  356.  
  357. gsec0_nam    swap d5
  358.     cmpi.b #80,d5
  359.     bne cant_find_name
  360.     
  361.     moveq #$7f,d4
  362.     lea $3a(a3),a4
  363.     move.l #$55555555,d7    
  364.     move.l #decoded_rootblock,a5
  365. dcblk_nam    move.l $200(a4),d6        
  366.     move.l (a4)+,d5        
  367.     and.l d7,d5    
  368.     and.l d7,d6
  369.     add.l d5,d5
  370.     or.l d6,d5        
  371.     move.l d5,(a5)+
  372.     dbf d4,dcblk_nam
  373.  
  374.     move.l #decoded_rootblock,a5
  375.     cmpi.l #$2,(a5)
  376.     bne cant_find_name
  377.     cmpi.l #$1,127*4(a5)
  378.     bne cant_find_name
  379.     lea 108*4(a5),a5
  380.     moveq #0,d0
  381.     move.b (a5),d0
  382.     cmpi.b #31,d0
  383.     bhi cant_find_name
  384.     lea $1(a5),a6
  385.     clr.b $00(a6,d0.w)    ;null terminate string
  386.     bsr showmessage
  387.     bsr shutdown
  388.     bsr init_ok_sound
  389.     rts
  390.  
  391. cant_find_name
  392.  
  393.     move.l #no_name,a6
  394.     bsr showmessage
  395.     bsr shutdown
  396.     bsr init_error_sound
  397.     rts
  398.  
  399.  
  400. ******************************************************************************
  401.  
  402.  
  403. Format_disk:
  404.     
  405.     bsr getdiskname        ;format disk proceddure
  406.     tst.w total_error(a2)
  407.     bmi terminated
  408.     bsr clear_track_status    
  409.     bsr reset_heads
  410.     clr.w total_error(a2)
  411.  
  412.     move.l #formting0,a6
  413.     move.w destination(a2),d0
  414.     beq.s drive0c
  415.     move.l #formting1,a6
  416. drive0c    add.w #3,d0
  417.     move.b #$7f,$100(a1)
  418.     bclr d0,$100(a1)    
  419.     bsr showmessage
  420.     bsr wait_motor
  421.     bsr position_heads
  422.     bsr get_strt_trk_bcd
  423.     cmpi.w #$10,disk_error(a2)
  424.     bne.s fdiskin
  425.     tst.w destination(a2)
  426.     beq nodisk0
  427.     bra nodisk1
  428. fdiskin    cmpi.w #$11,disk_error(a2)
  429.     beq write_pro
  430.  
  431.     move.w use_sides(a2),side_sel(a2)
  432.     andi.w #$1,side_sel(a2)
  433.  
  434. fmtlp    cmpi.w #3,clicked_box(a2)    ;stop format?
  435.     beq terminated
  436.     
  437.     tst.w side_sel(a2)
  438.     beq.s f_upper
  439.     bset #2,$100(a1)        
  440.     bra fside_set
  441. f_upper    bclr #2,$100(a1)        
  442.  
  443. fside_set    moveq #3,d7        
  444.     bsr cia_wait
  445.     bsr create_track
  446.  
  447.     move.w recopy_mode(a2),recopycount(a2)
  448. format_lp    bsr write_mfm
  449.     cmpi.w #1,check_mode(a2)
  450.     bne F_trackok        ;check this written track now?
  451.  
  452.     move.w #3,re_read(a2)    ;check track just formatted
  453. f_reread    cmpi.w #3,clicked_box(a2)
  454.     beq terminated
  455.     bsr read_mfm
  456.     tst.w disk_error(a2)    ;written track ok (now)?
  457.     beq.s f_trackok
  458.     subq.w #1,re_read(a2)    ;nope - maybe just a read error?
  459.     bne.s f_reread
  460.     cmpi.w #$10,disk_error(a2)    
  461.     beq diskgone1
  462.     subq.w #1,recopycount(a2)    
  463.     bpl format_lp
  464.     
  465. F_TrackOk    move.w disk_error(a2),d0
  466.     or.w d0,total_error(a2)
  467.     bsr show_dest_track_status
  468.  
  469.     cmpi.w #$2,use_sides(a2)
  470.     bne.s nxttrack3
  471.     eori.w #1,side_sel(a2)
  472.     bne nostep3
  473. nxttrack3    addq.w #1,track(a2)
  474.     bsr stepin
  475.     bsr next_track_bcd
  476.  
  477. nostep3    move.w endtrack(a2),d1
  478.     add.w #1,d1
  479.     cmp.w track(a2),d1
  480.     bne fmtlp
  481.     bsr ending
  482.     rts
  483.  
  484.  
  485. *****************************************************************************
  486.  
  487. Copy_disk:
  488.  
  489.     bsr clear_track_status    ;copy disk proceedure
  490.     bsr reset_heads
  491.     move.l #copying0,a6
  492.     move.w destination(a2),d0
  493.     bne.s drive0a
  494.     move.l #copying1,a6
  495. drive0a    bsr showmessage
  496.     move.b #$7f,$100(a1)    ;switch on both motors
  497.     move.b #$67,$100(a1)
  498.     bsr shortwait
  499.  
  500.     move.b #$77,$100(a1)    ;wait motor 0
  501.     bsr wait_motor
  502.     tst.w destination(a2)
  503.     bne.s din0
  504.     cmpi.w #$11,disk_error(a2)
  505.     beq write_pro
  506. din0    cmpi.w #$10,disk_error(a2)
  507.     beq nodisk0
  508.     move.b #$6f,$100(a1)    ;wait motor 1
  509.     bsr wait_motor
  510.     tst.w destination(a2)
  511.     beq.s din1
  512.     cmpi.w #$11,disk_error(a2)
  513.     beq write_pro
  514. din1    cmp.w #$10,disk_error(a2)
  515.     beq nodisk1
  516.     move.w use_sides(a2),side_sel(a2)
  517.     andi.w #$1,side_sel(a2)
  518.     clr.w total_error(a2)
  519.     
  520.     move.b #$67,$100(a1)
  521.     bsr position_heads
  522.     bsr get_strt_trk_bcd
  523.  
  524. copylp    move.w recopy_mode(a2),recopycount(a2)
  525. recopylp1    move.w #3,re_read(a2)
  526. reread2    cmpi.w #3,clicked_box(a2)
  527.     beq terminated
  528.     move.b #$7f,$100(a1)    ;select source drive
  529.     move.w destination(a2),d0
  530.     eor.w #1,d0
  531.     add.w #3,d0
  532.     bclr d0,$100(a1)
  533.     bsr read_mfm
  534.     tst.w disk_error(a2)
  535.     beq.s trackok2
  536.     cmpi.w #$10,disk_error(a2)
  537.     beq diskgone1
  538.     subq.w #1,re_read(a2)    ;try reading again..
  539.     bne.s reread2
  540.     bsr read_error_track    ;this source track has errors so
  541.     bra skipx2        ;try to copy it 'manually'
  542.  
  543. trackok2    bsr double_mfm
  544.     cmpi.w #1,check_mode(a2)    ;dont show source status if
  545.     beq noshsrc        ;checkmode 1 (+ track = OK)
  546. skipx2    bsr show_track_status
  547. noshsrc    move.w disk_error(a2),sourcestatus(a2)
  548.  
  549.     ori.b #$78,$100(a1)        ;select destination drive without
  550.     move.w destination(a2),d0    ;affecting disk side selection.
  551.     add.w #3,d0
  552.     bclr d0,$100(a1)
  553. recopylp2    bsr write_mfm
  554.     cmpi.w #$10,disk_error(a2)
  555.     beq diskgone1
  556.  
  557.     cmpi.w #1,check_mode(a2)    ;check this written track now?
  558.     bne notduring
  559.     tst.w sourcestatus(a2)    ;if source had error - dont check!
  560.     bne SrcErr
  561. chklp2    move.w #3,re_read(a2)    ;check track just copied
  562. reread3    cmpi.w #3,clicked_box(a2)
  563.     beq terminated
  564.     bsr read_mfm
  565.     tst.w disk_error(a2)    ;written track ok (now)?
  566.     beq.s trackok3
  567.  
  568.     subq.w #1,re_read(a2)    ;nope - maybe just a read error?
  569.     bne.s reread3
  570.     cmpi.w #$10,disk_error(a2)    
  571.     beq diskgone1
  572.     subq.w #1,recopycount(a2)    
  573.     bmi Trackok3
  574.     bsr remove_track_mark    
  575.     bra recopylp2
  576.  
  577. SrcErr    subq.w #1,recopycount(a2)    
  578.     bmi notduring        
  579.     bsr remove_track_mark    
  580.     bra recopylp1
  581.  
  582. TrackOk3    bsr show_dest_track_status
  583.     
  584. notduring    move.w disk_error(a2),d0
  585.     or.w d0,total_error(a2)
  586.     
  587.     cmpi.w #$2,use_sides(a2)
  588.     bne.s nxttrack2
  589.     eori.w #1,side_sel(a2)
  590.     bne nostep2
  591. nxttrack2    addq.w #1,track(a2)
  592.     move.b #$67,$100(a1)
  593.     bsr stepin
  594.     bsr next_track_bcd
  595.  
  596. nostep2    move.w endtrack(a2),d1
  597.     add.w #1,d1
  598.     cmp.w track(a2),d1
  599.     bne copylp
  600.     bsr ending
  601.     rts
  602.  
  603. *****************************************************************************
  604.  
  605. Check_disk:
  606.  
  607.     bsr clear_track_status    ;check disk proceedure
  608.     bsr reset_heads
  609.     move.l #checking0,a6
  610.     move.w destination(a2),d0
  611.     beq.s drive0b
  612.     move.l #checking1,a6
  613. drive0b    add.w #3,d0
  614.     move.b #$7f,$100(a1)
  615.     bclr d0,$100(a1)    
  616.     bsr showmessage
  617.     bsr wait_motor
  618.     bsr position_heads
  619.     bsr get_strt_trk_bcd
  620.     
  621.     cmpi.w #$10,disk_error(a2)
  622.     bne.s chk_go
  623. diskgone1    tst.w destination(a2)
  624.     beq nodisk0
  625.     bra nodisk1
  626.  
  627. chk_go    move.w use_sides(a2),side_sel(a2)
  628.     andi.w #$1,side_sel(a2)
  629.     clr.w total_error(a2)
  630.  
  631. chklp    move.w #3,re_read(a2)
  632. reread1    cmpi.w #3,clicked_box(a2)
  633.     beq terminated
  634.     bsr read_mfm
  635.     tst.w disk_error(a2)
  636.     beq.s trackok1
  637.     subq.w #1,re_read(a2)
  638.     bne.s reread1
  639.     cmpi.w #$10,disk_error(a2)
  640.     beq diskgone1
  641. trackok1    bsr show_track_status
  642.  
  643.     move.w disk_error(a2),d0
  644.     or.w d0,total_error(a2)
  645.  
  646.     cmpi.w #$2,use_sides(a2)
  647.     bne.s nxttrack1
  648.     eori.w #1,side_sel(a2)
  649.     bne nostep1
  650. nxttrack1    addq.w #1,track(a2)
  651.     bsr stepin
  652.     bsr next_track_bcd
  653.  
  654. nostep1    move.w endtrack(a2),d1
  655.     add.w #1,d1
  656.     cmp.w track(a2),d1
  657.     bne.s chklp
  658.     bsr checked
  659.     rts
  660.  
  661. ***************************************************************************
  662.  
  663. Ending:    tst.w check_mode(a2)
  664.     bne.s checked
  665.     bsr init_ok_sound
  666.     move.l #taskdone2,a6
  667.     bsr showmessage
  668.     bra finish
  669.  
  670. checked    tst.w total_error(a2)
  671.     beq.s noerrs1
  672.     bsr init_error_sound
  673.     move.l #taskdone0,a6
  674.     bsr showmessage
  675.     bra finish
  676. noerrs1    bsr init_ok_sound
  677.     move.l #taskdone1,a6
  678.     bsr showmessage
  679. finish    bsr shutdown
  680.     rts
  681.  
  682. terminated:
  683.  
  684.     move.w #1,dont_check(a2)
  685.     move.l #terminate,a6
  686.     bsr showmessage
  687.     bsr shutdown
  688.     bsr init_error_sound
  689.     rts
  690.  
  691. nodisk0:    move.w #1,dont_check(a2)
  692.     move.l #no_disk0,a6
  693.     bsr showmessage
  694.     bsr shutdown
  695.     bsr init_error_sound
  696.     rts
  697.  
  698. nodisk1:    move.w #1,dont_check(a2)
  699.     move.l #no_disk1,a6
  700.     bsr showmessage
  701.     bsr shutdown
  702.     bsr init_error_sound
  703.     rts
  704.  
  705. write_pro    move.w #1,dont_check(a2)
  706.     move.l #writepro,a6
  707.     bsr showmessage
  708.     bsr shutdown
  709.     bsr init_error_sound
  710.     rts
  711.  
  712. shutdown:    move.b #$ff,$100(a1)
  713.     move.b #$e7,$100(a1)
  714.     bsr vshrtwait
  715.     move.b #$ff,$100(a1)
  716.     clr.w irq_occured(a2)
  717.     rts
  718.  
  719. *****************************************************************************
  720.  
  721. Altersettings
  722.  
  723.     cmpi.w #9,d0
  724.     beq.s ch_dest
  725.     cmpi.w #5,d0
  726.     bne.s notchangedest
  727. ch_dest    eori.w #1,destination(a2)
  728.  
  729. notchangedest
  730.  
  731.     cmpi.w #6,d0        ;change check mode?
  732.     bne.s chksysok
  733.     cmpi.w #1,check_mode(a2)
  734.     bne.s no_chrc
  735.     addq.w #1,recopy_mode(a2)
  736.     cmpi.w #$9,recopy_mode(a2)
  737.     bls.s chksysok
  738.     clr.w recopy_mode(a2)
  739. no_chrc    addi.w #1,check_mode(a2)
  740.     cmpi.w #2,check_mode(a2)
  741.     bls.s chksysok
  742.     clr.w check_mode(a2)
  743. chksysok
  744.  
  745.     cmpi.w #$7,d0        ;change sides mode?
  746.     bne.s notchangesides
  747.     addq.w #1,use_sides(a2)
  748.     cmpi.w #$3,use_sides(a2)
  749.     bne.s notchangesides
  750.     clr.w use_sides(a2)
  751.  
  752. notchangesides
  753.     
  754.     cmpi.w #$8,d0        ;default?
  755.     bne.s notdefault
  756.     bsr go_default
  757.  
  758. notdefault
  759.  
  760.     bsr show_settings
  761.     clr.w clicked_box(a2)
  762.     bra wait_irq
  763.  
  764.  
  765. *****************************************************************************
  766.  
  767. *****************
  768. * Key Interrupt *
  769. *****************
  770.  
  771. keyirq    movem.l d0/a2,-(a7)
  772.     move.l #$bfe001,a2
  773.     btst #3,$d00(a2)
  774.     beq nokey
  775.     bset #6,$e00(a2)
  776.  
  777.     move.b #$08,$f00(a2)    
  778.     move.b #53,$600(a2)        ;set timer lo
  779.     move.b #00,$700(a2)        ;set timer hi (starts counter)
  780. kciawlp2    btst #0,$f00(a2)        ;wait for timeout
  781.     bne.s kciawlp2
  782.     
  783.     bclr #6,$e00(a2)
  784.     move.b $c00(a2),d0
  785.     not.b d0
  786.     ror.b #1,d0
  787.     move.l #vars,a2
  788.     move.b d0,keypressed(a2)
  789.     cmpi.b #$45,d0
  790.     bne.s not_esc
  791.     move.w #3,clicked_box(a2)
  792.  
  793. not_esc    andi.b #$7c,d0        ;shift held?
  794.     cmpi.b #$60,d0
  795.     bne.s nokey
  796.     tst.b keypressed(a2)
  797.     bpl.s shfton
  798.     clr.w shift_on(a2)
  799.     bra nokey
  800. shfton    move.w #1,shift_on(a2)
  801.  
  802. nokey    move.w #8,$dff09c
  803.     movem.l (a7)+,d0/a2
  804.     rte
  805.     
  806. *****************
  807. * VBL Interrupt *
  808. *****************
  809.  
  810.  
  811. Irq    movem.l a0-a6/d0-d7,-(a7)
  812.     move.w #$20,$dff09c
  813.     bsr irq_routines
  814.     movem.l (a7)+,a0-a6/d0-d7
  815.     rte
  816.     
  817. ********************************************************************************
  818.  
  819. irq_routines    
  820.  
  821.     move.l #$dff000,a0        ;move pointer
  822.     move.l #vars,a2
  823.  
  824.     tst.w rmb_latch(a2)
  825.     beq.s latch_off
  826.     btst #2,$16(a0)
  827.     beq.s rmbpress
  828.     clr.w rmb_latch(a2)
  829.     bra rmbpress
  830.  
  831. latch_off    btst #2,$16(a0)
  832.     bne.s rmbpress
  833.     eori.w #1,mouse_lock(a2)
  834.     move.w #1,rmb_latch(a2)
  835.     move.b $a(a0),oldmousex(a2)
  836.     move.b $b(a0),oldmousey(a2)
  837. rmbpress        
  838.     tst.w mouse_lock(a2)    
  839.     bne skipxy
  840.  
  841.     move.b $a(a0),d0
  842.     move.b $b(a0),d1
  843.     move.b d0,d2
  844.     move.b d1,d3
  845.     sub.b oldmousex(a2),d0
  846.     sub.b oldmousey(a2),d1
  847.     ext.w d0
  848.     ext.w d1
  849.     tst.w adjrng_mode(a2)
  850.     bne.s skp_y
  851.     add.w d0,pointery(a2)
  852. skp_y    add.w d1,pointerx(a2)
  853.     cmpi.w #$13c,pointerx(a2)
  854.     blt.s xinrr
  855.     move.w #$13c,pointerx(a2)
  856. xinrr    tst.w pointerx(a2)
  857.     bpl.s xinrl
  858.     clr.w pointerx(a2)
  859. xinrl    cmpi.w #$a0,pointery(a2)
  860.     blt.s yinrb
  861.     move.w #$a0,pointery(a2)
  862. yinrb    tst.w pointery(a2)
  863.     bpl.s yinrt
  864.     clr.w pointery(a2)
  865. yinrt    move.b d2,oldmousex(a2)
  866.     move.b d3,oldmousey(a2)
  867.  
  868.     move.l #pointersprite,a3    ;put new coords in sprite
  869.     tst.w adjrng_mode(a2)
  870.     beq.s sprnormal
  871.     clr.l (a3)
  872.     bra skipxy
  873. sprnormal    move.w pointerx(a2),d0
  874.     move.w pointery(a2),d1
  875.     add.w #$80,d0
  876.     add.w #$4a,d1
  877.     move.w d1,d2
  878.     add.w #$f,d2
  879.     move.b d1,(a3)
  880.     move.b d2,$2(a3)
  881.     clr.w d4
  882.     lsr.w #1,d0
  883.     bcc.s nocarry
  884.     moveq #1,d4
  885. nocarry    move.b d0,$1(a3)
  886.     btst #8,d1
  887.     beq.s novstrt
  888.     ori.w #4,d4
  889. novstrt    btst #8,d2
  890.     beq.s novstop
  891.     ori.w #4,d4
  892. novstop    move.b d4,$3(a3)
  893.  
  894. skipxy    move.w #1,irq_occured(a2)
  895.     tst.w button_latch(a2)    ;test button on boxes?
  896.     beq.s latchoff
  897.     btst #6,$bfe001
  898.     beq.s mouse_end
  899.     clr.w button_latch(a2)
  900.     bra.s mouse_end
  901. latchoff    btst #6,$bfe001
  902.     bne.s mouse_end
  903.     bsr test_boxes
  904.     bsr toggle_adjrange
  905.     move.w #1,button_latch(a2)
  906.  
  907. mouse_end    tst.w volume(a2)
  908.     beq.s soundend
  909.     move.w volume(a2),$a8(a0)
  910.     move.w volume(a2),$b8(a0)
  911.     move.w volume(a2),$c8(a0)
  912.     move.w volume(a2),$d8(a0)
  913.     subq.w #2,volume(a2)
  914.     bpl.s soundend
  915.     move.w #$f,$96(a0)
  916.     clr.w volume(a2)
  917. soundend    rts
  918.  
  919.  
  920. ****************************************************************************
  921.  
  922. **********************
  923. * Main disk routines *
  924. **********************
  925.  
  926. *************
  927. * Read data *
  928. *************
  929.  
  930. read_mfm    move.l #$dff000,a0        ;load in a track side into
  931.     move.l #$bfd000,a1        ;mfm buffer
  932.     move.l #vars,a2
  933.     tst.w side_sel(a2)
  934.     beq.s upperside
  935.     bset #2,$100(a1)        
  936.     bra side_set
  937. upperside    bclr #2,$100(a1)        
  938.  
  939. side_set    move.w #2,$9c(a0)
  940.     clr.w disk_error(a2)
  941.     moveq #2,d7        ;let head settle.
  942.     bsr cia_wait
  943.     move.l #mfm_buffer,a3
  944.     move.l a3,$20(a0)        ;mfm buffer location
  945.     move.w #$4000,$24(a0)    
  946.     move.w #$8010,$96(a0)    
  947.     move.w #$6800,$9e(a0)    
  948.     move.w #$9500,$9e(a0)
  949.     move.w #$4489,$7e(a0)    
  950.     move.w #$98e0,$24(a0)    ;no of words to load 
  951.     move.w #$98e0,$24(a0)    
  952.     bsr show_track_no_bcd
  953.     move.w #2000,d3        
  954. w_dma_end    moveq #1,d7        ;wait 3 seconds for sync or
  955.     bsr cia_wait        ;time out.
  956.     btst #1,$1f(a0)        
  957.     bne.s dma_end
  958.     dbf d3,w_dma_end
  959.     move.w #1,re_read(a2)
  960.     btst #2,$1001(a1)        
  961.     bne.s no_sync
  962.     move.w #$10,disk_error(a2)    ;disk removed error.
  963.     bra dma_end
  964. no_sync    move.w #$2,disk_error(a2)    ;no sync / time out (error 2)
  965. dma_end    move.w #$4000,$24(a0)    
  966.     move.w #$10,$96(a0)        
  967.  
  968. **************
  969. * Check data *
  970. **************
  971.  
  972.  
  973. Check_Mfm    tst.w disk_error(a2)    
  974.     bne errors
  975.     move.l #mfm_buffer,a3    ;check read mfm for errors
  976.     cmpi.w #$4489,(a3)
  977.     beq.s sync1
  978.     cmpi.w #$4489,$2(a3)    ;check for 1st sync
  979.     beq.s sync1
  980.     move.w #2,disk_error(a2)
  981.     bra errors
  982.  
  983. sync1    moveq #$a,d1        ;11 sectors to find
  984. chek_loop    move.w #$4489,d2        ;sync
  985.     cmp.w $2(a3),d2
  986.     bne.s one_sync
  987.     addq.w #2,a3
  988. one_sync    move.w d2,-$2(a3)        ;tidy up pre-sync locations
  989.     move.l #$aaaaaaaa,-$6(a3)
  990.     btst #0,-$7(a3)
  991.     beq.s clock_ok
  992.     move.w #$2aaa,-$6(a3)
  993. clock_ok
  994.     lea $2a(a3),a4        ;check header checksum
  995.     bsr decode_long
  996.     move.l d5,d2    
  997.     lea $2(a3),a4        
  998.     bsr decode_long
  999.     cmp.l d4,d2
  1000.     beq hdrchksm_ok
  1001.     move.w #4,disk_error(a2)    ;header checksum error 4
  1002.     bra errors
  1003. hdrchksm_ok
  1004.     move.l d5,d2        ;track mark ok?
  1005.     swap d2
  1006.     move.w track(a2),d7
  1007.     lsl.w #1,d7
  1008.     or.w side_sel(a2),d7
  1009.     eori.w #1,d7
  1010.     cmp.b d7,d2
  1011.     beq header_ok
  1012.     move.w #5,disk_error(a2)    ;track mark error 5
  1013.     bra errors
  1014. header_ok
  1015.     lsr.w #8,d2
  1016.     cmpi.b #$ff,d2
  1017.     beq header_ok2
  1018.     move.w #5,disk_error(a2)    ;no $ff error 5
  1019.     bra errors
  1020. header_ok2
  1021.     lea $32(a3),a4        ;check diskblock checksum
  1022.     bsr decode_long        
  1023.     bsr data_checksum        
  1024.     cmp.l d4,d5
  1025.     beq dbchksm_ok
  1026.     move.w #6,disk_error(a2)    ;data block checksum_error
  1027.     bra errors
  1028. dbchksm_ok                
  1029.     move.w #$4489,d2        ;find next sync
  1030.     add.w #$440,a3
  1031.     cmp.w (a3),d2
  1032.     beq.s next_sync
  1033.                 
  1034.     add.w #$1c0,a3        ;no sync so this is either the gap 
  1035.     move.l a3,d6        ;or an error!
  1036.     subi.l #mfm_buffer,d6
  1037.     move.w #$31be,d7        ;attempt to find sync after gap
  1038.     sub.w d6,d7        
  1039.     lsr.w #1,d7        ;amount of words till end of mfm
  1040. find_sag    cmp.w (a3)+,d2
  1041.     dbeq d7,find_sag
  1042.     subq.w #2,a3
  1043.     move.l a3,firstsync(a2)    ;store 1st sync after gap address
  1044.     tst.w d7
  1045.     bpl next_sync        
  1046.     move.w #3,disk_error(a2)    ;no sync after gap error 3
  1047.     bra errors
  1048. next_sync    dbf d1,chek_loop
  1049. errors    rts
  1050.  
  1051. *****************************************
  1052. * Double MFM Length to make write track *
  1053. *****************************************
  1054.  
  1055. double_mfm
  1056.     move.w #$4489,d2
  1057.     move.l firstsync(a2),a3    ;addr of 1st sync after original gap
  1058.     cmp.w $2(a3),d2        
  1059.     bne.s onesync
  1060.     addq.w #2,a3
  1061. onesync    move.w d2,-(a3)        ;tidy up pre-sync locations
  1062.     move.l #$aaaaaaaa,d2    ;(make sure theres 2 syncs and
  1063.     move.w #$7f,d6        ;fill most of gap with $AAAA.)
  1064. loop...    move.l d2,-(a3)        
  1065.     dbf d6,loop...        ;a3 = start of mfm for write.
  1066.     move.l a3,write_addr(a2)
  1067.  
  1068.     move.l #mfm_buffer,a4
  1069.     lea $31c0(a4),a5
  1070.     move.w #$4489,d2    
  1071.     cmp.w $2(a4),d2        ;locate the sync before header at
  1072.     bne.s loopd        ;start of mfm (1st sector read)
  1073.     addq.w #2,a4
  1074. loopd    cmp.w -(a5),d2        ;locate last sync in mfm (2nd
  1075.     bne.s loopd        ;occurance of that sector)
  1076.     
  1077.     move.l #$ffffffff,$44(a0)    ;copy mfm data end to end,aligned
  1078.     clr.l $64(a0)        ;on same sync using blitter
  1079.     move.l a4,$50(a0)        
  1080.     move.l a5,$54(a0)
  1081.     move.w #$09f0,$40(a0)
  1082.     move.w #$31e0,$58(a0)
  1083.     bsr wait_blit
  1084.     rts
  1085.  
  1086. *******************************
  1087. * Attempt to Copy error track *
  1088. *******************************
  1089.  
  1090. Read_Error_Track
  1091.  
  1092.     move.l #mfm_buffer,a3    ;re-read 2 x track length
  1093.     move.l a3,$20(a0)        
  1094.     move.w #$1002,$9c(a0)    
  1095.     move.w #$8010,$96(a0)    
  1096.     move.w #$7f00,$9e(a0)    
  1097.     move.w #$9500,$9e(a0)    
  1098.     move.w #$4000,$24(a0)    
  1099.     move.w #$b2c0,$24(a0)    
  1100.     move.w #$b2c0,$24(a0)    
  1101.     
  1102.     move.w #3000,d3        
  1103. w_dma2    moveq #1,d7        ;wait 3 seconds for sync or
  1104.     bsr cia_wait        ;time out.
  1105.     btst #1,$1f(a0)        
  1106.     bne.s dma_end2
  1107.     dbf d3,w_dma2
  1108.     move.w #1,re_read(a2)
  1109.     move.w #$2,disk_error(a2)    ;no sync - time out (error 2)
  1110.     move.w #$4000,$24(a0)    ;special code for disk
  1111.     move.w #$10,$96(a0)        ;disable disk dma
  1112.     bra no_copy
  1113.  
  1114. dma_end2    move.w #$4000,$24(a0)    ;special code for disk
  1115.     move.w #$10,$96(a0)        ;disable disk dma
  1116.  
  1117.     move.w #$4489,d2        ;try to find the gap
  1118.     cmp.w $2(a3),d2
  1119.     bne.s et_sync1
  1120.     add.w #2,a3
  1121. et_sync1    move.w #$240,d7        ;next sync should be within
  1122. et_loop    cmp.w (a3)+,d2        ;about $440 bytes. If it isnt -
  1123.     beq.s et_sync        ;call this the gap
  1124.     dbf d7,et_loop
  1125.     bra gotet_gap
  1126. et_sync    addq.w #2,a3        ;skip possible 2nd sync
  1127.     bra et_sync1
  1128.  
  1129. gotet_gap    cmp.l #mfm_buffer+$6580,a3
  1130.     bls.s fetstart
  1131.     move.l #mfm_buffer,a3    ;track is totally shot!
  1132. fetstart    move.l a3,write_addr(a2)
  1133.  
  1134.     move.w #$195f,d7        ;try to locate and fix up sync
  1135. pusynclp    cmp.w (a3),d2        ;and pre-sync words
  1136.     bne.s not_sync        
  1137.     addq.w #$2,a3
  1138.     cmp.w (a3),d2
  1139.     bne.s fasyncpos
  1140.     addq.w #$2,a3
  1141. fasyncpos    move.l #$44894489,-$4(a3)
  1142.     move.l #$aaaaaaaa,-$8(a3)
  1143. not_sync    addq.w #2,a3
  1144.     dbf d7,pusynclp    
  1145. no_copy    rts
  1146.     
  1147. ***************
  1148. * Write track *
  1149. ***************
  1150.  
  1151. Write_mfm    move.l write_addr(a2),$20(a0)    ;mfm buffer location
  1152.     move.w #$1002,$9c(a0)    ;clear disk irq flags
  1153.     move.w #$8010,$96(a0)    ;enable dma
  1154.     move.w #$4000,$24(a0)    ;special code for disk
  1155.     move.w #$7f00,$9e(a0)    ;diskcontrol
  1156.     move.w #$9100,$9e(a0)
  1157.     move.w #$d940,$24(a0)    ;no of words to write to disk
  1158.     move.w #$d940,$24(a0)    ;from mfm buffer
  1159.     bsr show_track_no_bcd
  1160. waitdirq2    btst #1,$1f(a0)        
  1161.     beq.s waitdirq2        
  1162.     move.w #$4000,$24(a0)    ;special code for disk
  1163.     move.w #$10,$96(a0)        ;disable dma
  1164.     rts
  1165.  
  1166. ******************************************************************************
  1167.  
  1168. *******************************************
  1169. * Small disk hardware/software procedures *
  1170. *******************************************
  1171.  
  1172. decode_long
  1173.  
  1174.     move.l #$55555555,d7    ;returns decoded longword in
  1175.     move.l (a4),d5        ;d5
  1176.     move.l $4(a4),d6        
  1177.     and.l d7,d5        ;and checksum in d4
  1178.     and.l d7,d6
  1179.     move.l d5,d4
  1180.     eor.l d6,d4
  1181.     add.l d5,d5
  1182.     or.l d6,d5        
  1183.     rts
  1184.  
  1185. data_checksum
  1186.  
  1187.     move.l #checklong,a5
  1188.     clr.l (a5)
  1189.     move.l #$55555555,$44(a0)    ;f/lwmask
  1190.     move.l a5,$54(a0)        ;destination
  1191.     move.l a5,$4c(a0)        ;source b
  1192.     lea $3a(a3),a4        
  1193.     move.l a4,$50(a0)        ;source a
  1194.     move.w #$fffc,$62(a0)    ;blit mod b
  1195.     move.l #$0000fffc,$64(a0)    ;blit mod a,d
  1196.     move.l #$0d3c0000,$40(a0)    ;use ab,d with 3c minterm
  1197.     move.w #$4002,$58(a0)    ;100 * 4 bytes
  1198.     bsr wait_blit
  1199.     move.l (a5),d4
  1200.     rts
  1201.  
  1202. reset_heads
  1203.  
  1204.     move.b #$fd,$100(a1)    
  1205.     move.b #$e5,$100(a1)
  1206.     tst.w track(a2)        ;if track is already 0, step
  1207.     bne.s skp_stp        ;to track 1 first, to enusure
  1208.     bsr stepin        ;disk_chng is reset.
  1209.  
  1210. skp_stp    move.b #$e7,d6        
  1211.     moveq #-1,d4
  1212.     moveq #-1,d5
  1213.  
  1214. seek0    btst #3,d6
  1215.     bne.s skipdf0
  1216.     move.b #$f7,$100(a1)    
  1217.     bsr vshrtwait
  1218.     btst #4,$1001(a1)
  1219.     bne.s stepdf0
  1220.     bset #3,d6
  1221.     bra skipdf0
  1222. stepdf0    addq.w #1,d4
  1223.     
  1224. skipdf0    btst #4,d6
  1225.     bne.s skipdf1
  1226.     move.b #$ef,$100(a1)
  1227.     bsr vshrtwait
  1228.     btst #4,$1001(a1)
  1229.     bne.s stepdf1
  1230.     bset #4,d6
  1231.     bra skipdf1
  1232. stepdf1    addq.w #1,d5
  1233.  
  1234. skipdf1    cmpi.b #$ff,d6
  1235.     beq.s zerod
  1236.     move.b d6,$100(a1)
  1237.     bsr vshrtwait
  1238.     bsr step_pulse
  1239.     bra.s seek0
  1240.  
  1241. zerod    moveq #12,d7
  1242.     bsr cia_wait
  1243.     clr.w track(a2)
  1244.     rts
  1245.  
  1246. position_heads
  1247.  
  1248.     move.w starttrack(a2),d0    ;positions heads over selected track
  1249. moveheads    cmp.w track(a2),d0        ;as defined by the range markers
  1250.     beq.s movedone
  1251.     bclr #1,$100(a1)
  1252.     bsr vshrtwait    
  1253.     bsr step_pulse
  1254.     addq.w #1,track(a2)
  1255.     bra moveheads
  1256. movedone    moveq #12,d7
  1257.     bsr cia_wait
  1258.     rts
  1259.  
  1260.  
  1261. Stepout    bset #1,$100(a1)        ;for use if read follows
  1262.     bra.s step
  1263. Stepin    bclr #1,$100(a1)
  1264. step    bsr vshrtwait    
  1265.     bsr step_pulse
  1266.     moveq #14,d7
  1267.     bsr cia_wait
  1268.     rts
  1269.  
  1270. step_pulse
  1271.  
  1272.     bclr #0,$100(a1)
  1273.     bsr vshrtwait
  1274.     bset #0,$100(a1)
  1275.     moveq #4,d7
  1276.     bsr cia_wait
  1277.     rts
  1278.  
  1279. wait_motor
  1280.     clr.w disk_error(a2)
  1281.     move.w #1000,d1
  1282. wait_m    moveq #1,d7
  1283.     bsr cia_wait
  1284.     btst #5,$1001(a1)
  1285.     beq.s speed_ok
  1286.     dbf d1,wait_m
  1287.     move.w #$10,disk_error(a2)
  1288.     bra write_en
  1289. speed_ok    btst #3,$1001(a1)
  1290.     bne.s write_en
  1291.     move.w #$11,disk_error(a2)
  1292. write_en    rts
  1293.  
  1294.  
  1295. cia_wait    move.b #$08,$f00(a1)    
  1296.     move.b #$cc,$600(a1)    ;set timer lo
  1297.     move.b #$02,$700(a1)    ;set timer hi (starts counter)
  1298. ciawlp2    btst #0,$f00(a1)        ;wait for timeout
  1299.     bne.s ciawlp2
  1300.     subq.w #1,d7
  1301.     bne.s cia_wait        ;d7 = milliseconds to wait.
  1302.     rts
  1303.  
  1304.  
  1305. shortwait    moveq #1,d7
  1306.     bsr cia_wait
  1307.     rts
  1308.  
  1309.  
  1310. vshrtwait    nop
  1311.     nop    
  1312.     nop
  1313.     nop
  1314.     nop
  1315.     nop
  1316.     nop
  1317.     nop
  1318.     nop
  1319.     nop
  1320.     nop    
  1321.     nop
  1322.     nop
  1323.     rts
  1324.  
  1325. **********************************************************************************
  1326.  
  1327. ****************************
  1328. * Kwikcopy system routines *
  1329. ****************************
  1330.  
  1331. test_boxes
  1332.  
  1333.     move.l #box_areas,a3
  1334.     moveq #1,d3
  1335. boxloop    moveq #0,d4
  1336.     moveq #0,d5
  1337.     moveq #0,d6
  1338.     moveq #0,d7
  1339.     move.b (a3)+,d4
  1340.     move.b (a3)+,d5
  1341.     move.b (a3)+,d6
  1342.     move.b (a3)+,d7
  1343.     lsl.w #3,d4
  1344.     lsl.w #3,d5
  1345.     lsl.w #3,d6
  1346.     lsl.w #3,d7
  1347.     add.w #20+4,d4
  1348.     add.w #20+4,d6
  1349.     sub.w #24-4,d5
  1350.     sub.w #24-4,d7
  1351.     cmp.w pointery(a2),d4
  1352.     bhi.s missbox
  1353.     cmp.w pointery(a2),d6
  1354.     bls.s missbox
  1355.     cmp.w pointerx(a2),d5
  1356.     bhi.s missbox
  1357.     cmp.w pointerx(a2),d7
  1358.     bls.s missbox
  1359.     move.w d3,clicked_box(a2)
  1360.     rts
  1361. missbox    addq.w #1,d3
  1362.     cmpi.w #$10,d3
  1363.     bne.s boxloop
  1364.     rts
  1365.  
  1366.  
  1367. toggle_adjrange
  1368.  
  1369.     move.w adjrng_mode(a2),d0    ;alter start/stop tracks.
  1370.     beq init_mark
  1371.     tst.w button_latch(a2)
  1372.     bne.s noadjesc
  1373.     clr.w adjrng_mode(a2)
  1374. noadjesc    rts
  1375.  
  1376. init_mark    move.w starttrack(a2),d0    ;initiate move start/end markers.
  1377.     move.w endtrack(a2),d2
  1378.     lsl.w #2,d0
  1379.     lsl.w #2,d2
  1380.     subq.w #8,d0
  1381.     subq.w #2,d2
  1382.     move.w d0,d1
  1383.     move.w d2,d3
  1384.     add.w #16,d1
  1385.     add.w #16,d3
  1386.     move.w pointerx(a2),d4
  1387.     move.w pointery(a2),d5
  1388.     cmp.w d0,d4
  1389.     blt.s ncstartt
  1390.     cmp.w d1,d4
  1391.     bgt.s ncstartt
  1392.     cmp.w #14,d5
  1393.     blt.s ncstartt
  1394.     cmp.w #24,d5
  1395.     bgt.s ncstartt
  1396.     move.w #1,adjrng_mode(a2)    ;adjust start track mode on     
  1397.     rts
  1398.  
  1399. ncstartt    cmp.w d2,d4
  1400.     blt.s ncendt
  1401.     cmp.w d3,d4
  1402.     bgt.s ncendt
  1403.     cmp.w #44,d5
  1404.     blt.s ncendt
  1405.     cmp.w #54,d5
  1406.     bgt.s ncendt
  1407.     move.w #2,adjrng_mode(a2)    ;adjust end track mode on     
  1408. ncendt    rts
  1409.     
  1410.  
  1411. adjust_range
  1412.  
  1413.     move.w adjrng_mode(a2),d0    ;alter start/stop tracks.
  1414.     beq notadj
  1415.     cmpi.w #2,d0
  1416.     beq.s alt_end
  1417.     
  1418. alt_strt    move.w pointerx(a2),d0
  1419.     lsr.w #2,d0
  1420.     cmp.w endtrack(a2),d0
  1421.     bls.s strackok
  1422.     move.w endtrack(a2),d0
  1423. strackok    move.w d0,starttrack(a2)
  1424.     bsr convert
  1425.     move.l #trackstartsprite+4,a3
  1426.     bsr trkdigits
  1427.     bra setmarkerpositions
  1428.  
  1429. alt_end    move.w pointerx(a2),d0
  1430.     lsr.w #2,d0
  1431.     cmp.w starttrack(a2),d0
  1432.     bhi.s etrackok
  1433.     move.w starttrack(a2),d0
  1434. etrackok    move.w d0,endtrack(a2)
  1435.     bsr convert
  1436.     move.l #trackendsprite+96,a3
  1437.     bsr trkdigits
  1438.  
  1439. setmarkerpositions
  1440.  
  1441.     move.w starttrack(a2),d0    ;track marker x coords
  1442.     lsl.w #1,d0
  1443.     add.w #$3b,d0
  1444.     move.b d0,trackstartsprite+1
  1445.     move.w endtrack(a2),d0
  1446.     lsl.w #1,d0
  1447.     add.w #$3e,d0
  1448.     move.b d0,trackendsprite+1
  1449. notadj    rts
  1450.  
  1451.  
  1452. go_default
  1453.     
  1454.     move.w #$2,check_mode(a2)
  1455.     clr.w recopy_mode(a2)
  1456.     move.w #2,use_sides(a2)
  1457.     move.w #1,destination(a2)
  1458.     move.w #0,starttrack(a2)
  1459.     move.w #79,endtrack(a2)
  1460.     clr.w side_sel(a2)
  1461.     move.w starttrack(a2),d0
  1462.     bsr convert
  1463.     move.l #trackstartsprite+4,a3
  1464.     bsr trkdigits
  1465.     move.w endtrack(a2),d0
  1466.     bsr convert
  1467.     move.l #trackendsprite+96,a3
  1468.     bsr trkdigits
  1469.     bsr setmarkerpositions
  1470.     bsr clear_track_status
  1471.     bsr get_strt_trk_bcd
  1472.     bsr show_track_no_bcd
  1473.     rts
  1474.  
  1475.  
  1476. convert    clr.w d1
  1477.     andi.w #$ff,d0
  1478.     move.b d0,d1        ;convert hex in d0 to BCD in
  1479.     andi.b #$f,d1        ;d1
  1480.     cmpi.b #$9,d1
  1481.     bls.s sk1
  1482.     sub.b #$a,d1
  1483.     ori.b #$10,d1
  1484. sk1    move.w d0,d2
  1485.     lsr.w #4,d2
  1486.     subq.w #1,d2
  1487.     bmi.s sk2
  1488.     move.b #$16,d3
  1489. bcdlp1    move.b #4,ccr
  1490.     abcd d3,d1
  1491.     dbf d2,bcdlp1
  1492. sk2    rts
  1493.  
  1494. trkdigits    clr.w d2            ;put figures in track sprites
  1495.     move.b d1,d2
  1496.     lsr.b #4,d1
  1497.     move.l #ONEplanefont+$10,a4
  1498.     add.w d1,a4
  1499.     move.b (a4),(a3)
  1500.     move.b 96*1(a4),$4(a3)
  1501.     move.b 96*2(a4),$8(a3)
  1502.     move.b 96*3(a4),$c(a3)
  1503.     move.b 96*4(a4),$10(a3)
  1504.     move.b 96*5(a4),$14(a3)
  1505.     andi.w #$f,d2
  1506.     move.l #ONEplanefont+$10,a4
  1507.     add.w d2,a4
  1508.     move.b (a4),$1(a3)
  1509.     move.b 96*1(a4),$5(a3)
  1510.     move.b 96*2(a4),$9(a3)
  1511.     move.b 96*3(a4),$d(a3)
  1512.     move.b 96*4(a4),$11(a3)
  1513.     move.b 96*5(a4),$15(a3)
  1514.     rts
  1515.  
  1516. show_settings
  1517.  
  1518.     move.l #$dff000,a0
  1519.     move.l #vars,a2
  1520.     move.l #$ffffffff,$44(a0)
  1521.     move.l #$09f00000,$40(a0)
  1522.  
  1523.     move.l #checktxt,a6        ;show check mode
  1524.     move.w check_mode(a2),d1
  1525.     mulu #17,d1
  1526.     add.w d1,a6
  1527.     moveq #24,d6
  1528.     moveq #4,d7
  1529.     bsr display_sentence4
  1530.  
  1531.     move.l #sidestext,a6    ;show sides mode
  1532.     move.w use_sides(a2),d1
  1533.     mulu #$6,d1
  1534.     add.l d1,a6
  1535.     moveq #10,d6
  1536.     moveq #15,d7
  1537.     bsr display_sentence4
  1538.  
  1539.     move.l #retrytxt,a6        ;show retries figure
  1540.     cmpi.w #1,check_mode(a2)    ;(if check mode 1)
  1541.     bne.s show_src
  1542.     move.w recopy_mode(a2),d1
  1543.     lsl.w #1,d1
  1544.     add.w d1,a6
  1545.     moveq #31,d6
  1546.     moveq #4,d7
  1547.     bsr display_sentence4
  1548.  
  1549. show_src    move.w destination(a2),d0    ;show source/destination number
  1550.     eori.w #1,d0
  1551.     mulu #$5,d0
  1552.     move.l #sourcetxt,a6    
  1553.     add.w d0,a6
  1554.     moveq #23,d6
  1555.     moveq #8,d7
  1556.     bsr display_sentence4
  1557. show_dst    move.w destination(a2),d0    
  1558.     mulu #$5,d0
  1559.     move.l #sourcetxt,a6    
  1560.     add.w d0,a6
  1561.     moveq #23,d6
  1562.     moveq #11,d7
  1563.     bsr display_sentence4
  1564.     rts
  1565.  
  1566. blit_wait    btst #$6,$2(a0)
  1567.     bne.s blit_wait
  1568.     rts
  1569.  
  1570. showmessage
  1571.  
  1572.     move.l a6,-(a7)
  1573.     move.l #nullmsg,a6
  1574.     bsr message
  1575.     move.l (a7)+,a6
  1576.     bsr message
  1577.     rts
  1578.  
  1579. message    move.l #screen+(175*176)+3,a4
  1580.     clr.w d1            ;set a6 = addr of null terminated
  1581. messagelp    clr.w d0            ;string. Plot in ONE plane font.
  1582.     move.b (a6)+,d0    
  1583.     beq.s mess_end
  1584.     sub.b #$20,d0
  1585.     bsr printchar
  1586.     addq.w #1,d1
  1587.     bra messagelp
  1588. mess_end    rts
  1589.  
  1590.  
  1591. printchar    move.l a4,-(a7)
  1592.     move.l #ONEplanefont,a3    ;d0 = font char number,d1=x pos
  1593.     add.w d0,a3        ;set a4 to screen line address
  1594.     add.w d1,a4        
  1595.     move.b (a3),(a4)
  1596.     move.b 96*1(a3),176(a4)
  1597.     move.b 96*2(a3),352(a4)
  1598.     move.b 96*3(a3),528(a4)
  1599.     move.b 96*4(a3),704(a4)
  1600.     move.b 96*5(a3),880(a4)
  1601.     move.l (a7)+,a4
  1602.     rts
  1603.  
  1604. show_track_status
  1605.  
  1606.     move.l #errornos,a3        ;fill track block status for this
  1607.     move.l #screen+(35*176)+1,a4    ;disk side
  1608.     tst.w side_sel(a2)
  1609.     beq.s upper    
  1610.     add.w #176*6,a4
  1611. upper    move.w track(a2),d7
  1612.     clr.w d0
  1613.     btst #0,d7
  1614.     beq.s leftnyb
  1615.     moveq #4,d0
  1616. leftnyb    lsr.w #1,d7
  1617.     add.w d7,a4
  1618.     move.w disk_error(a2),d7
  1619.     beq.s noerror
  1620.     add.w #44,a4
  1621. noerror    add.w d7,a3
  1622.  
  1623. plotTmark    move.b (a3),d7
  1624.     lsr.b d0,d7
  1625.     or.b d7,(a4)
  1626.     move.b $8(a3),d7
  1627.     lsr.b d0,d7
  1628.     or.b d7,176(a4)
  1629.     move.b $10(a3),d7
  1630.     lsr.b d0,d7
  1631.     or.b d7,352(a4)
  1632.     move.b $18(a3),d7
  1633.     lsr.b d0,d7
  1634.     or.b d7,528(a4)
  1635.     move.b $20(a3),d7
  1636.     lsr.b d0,d7
  1637.     or.b d7,704(a4)
  1638.     rts
  1639.  
  1640. show_dest_track_status
  1641.  
  1642.     move.l #errornos,a3        ;fill track block status for this
  1643.     move.l #screen+(35*176)+1,a4    ;disk side
  1644.     tst.w side_sel(a2)
  1645.     beq.s upper2
  1646.     add.w #176*6,a4
  1647. upper2    move.w track(a2),d7
  1648.     clr.w d0
  1649.     btst #0,d7
  1650.     beq.s leftnyb2
  1651.     moveq #4,d0
  1652. leftnyb2    lsr.w #1,d7
  1653.     add.w d7,a4
  1654.     move.w disk_error(a2),d7
  1655.     beq.s noerror2
  1656.     add.w #88,a4
  1657. noerror2    add.w d7,a3
  1658.     bra plotTmark
  1659.  
  1660. remove_track_mark
  1661.  
  1662.     move.l #screen+(35*176)+1,a4    ;erase track mark for this
  1663.     tst.w side_sel(a2)        ;position only
  1664.     beq.s upper3
  1665.     add.w #176*6,a4
  1666. upper3    move.w track(a2),d7
  1667.     move.b #$f,d0
  1668.     btst #0,d7
  1669.     beq.s leftnyb3
  1670.     not.b d0
  1671. leftnyb3    lsr.w #1,d7
  1672.     add.w d7,a4
  1673.     
  1674.     moveq #2,d7
  1675. cltmlp    and.b d0,(a4)
  1676.     and.b d0,176(a4)
  1677.     and.b d0,352(a4)
  1678.     and.b d0,528(a4)
  1679.     and.b d0,704(a4)
  1680.     add.w #44,a4
  1681.     dbf d7,cltmlp
  1682.     rts
  1683.  
  1684. clear_track_status
  1685.  
  1686.     clr.l $64(a0)
  1687.     move.l #$ffffffff,$44(a0)
  1688.     move.l #screen+(176*35),$54(a0)
  1689.     move.l #$01000000,$40(a0)
  1690.     move.w #$0b16,$58(a0)
  1691.     bsr wait_blit
  1692.     rts
  1693.  
  1694. wait_blit    btst #$6,$2(a0)
  1695.     bne.s wait_blit
  1696.     rts    
  1697.  
  1698. display_sentence4
  1699.  
  1700.     movem.l a2-a5/d5-d7,-(a7)
  1701.     move.l #FOURplanefont,a3    ;display a string of characters
  1702.     move.l #asciiconv,a5    ;(terminated in $a) using the 4 plane
  1703.     mulu #176*8,d7        ;font. A6 =charstring address
  1704.     add.w d6,d7        ;d6 = x, d7 = y. All registers
  1705.     move.l #screen+(176*30),a4    ;preserved EXCEPT A6
  1706.     add.w d7,a4
  1707.     moveq #0,d5
  1708. snt_loop1    move.b (a6)+,d5
  1709.     cmpi.b #$a,d5
  1710.     beq.s sent_done
  1711.     move.b $00(a5,d5.w),d5
  1712.     lea $00(a3,d5.w),a2
  1713.     moveq #7,d7
  1714. snt_loop2    move.b (a2),(a4)
  1715.     add.w #58,a2
  1716.     add.w #44,a4
  1717.     move.b (a2),(a4)
  1718.     add.w #58,a2
  1719.     add.w #44,a4
  1720.     move.b (a2),(a4)
  1721.     add.w #58,a2
  1722.     add.w #44,a4
  1723.     move.b (a2),(a4)
  1724.     add.w #58,a2
  1725.     add.w #44,a4
  1726.     dbf d7,snt_loop2
  1727.     sub.w #1407,a4
  1728.     bra snt_loop1
  1729. sent_done    movem.l (a7)+,a2-a5/d5-d7
  1730.     rts
  1731.  
  1732.  
  1733. get_strt_trk_bcd
  1734.  
  1735.     move.w starttrack(a2),d0    ;gets the start track number as BCD
  1736.     bsr convert
  1737.     move.b d1,track_bcd(a2)
  1738.     rts
  1739.  
  1740. show_track_no_bcd
  1741.  
  1742.     movem.l d0/d1/d7/a4/a3,-(a7)
  1743.     clr.w d0
  1744.     move.b track_bcd(a2),d0
  1745.     move.w d0,d7
  1746.     lsr.w #4,d0
  1747.     andi.w #$f,d7
  1748.     add.w #$10,d0
  1749.     add.w #$10,d7
  1750.     move.l #screen+(63*176),a4
  1751.     moveq #9,d1
  1752.     bsr printchar
  1753.     move.w d7,d0
  1754.     moveq #10,d1
  1755.     bsr printchar
  1756.     moveq #$0e,d0
  1757.     moveq #11,d1
  1758.     bsr printchar
  1759.     move.w #"U"-$20,d0
  1760.     move.w side_sel(a2),d1
  1761.     mulu #9,d1
  1762.     sub.w d1,d0
  1763.     moveq #12,d1
  1764.     bsr printchar
  1765.     movem.l (a7)+,d0/d1/d7/a4/a3
  1766.     rts
  1767.  
  1768. next_track_bcd
  1769.  
  1770.     move.b track_bcd(a2),d0
  1771.     move.w #4,CCR
  1772.     moveq #1,d1
  1773.     abcd.b d1,d0
  1774.     move.b d0,track_bcd(a2)
  1775.     rts
  1776.                 
  1777. init_ok_sound
  1778.     
  1779.     move.w #$d0,$a6(a0)
  1780.     move.w #$d2,$b6(a0)
  1781.     move.w #$d0,$c6(a0)
  1782.     move.w #$d2,$d6(a0)
  1783. sound    move.l #sounddata,$a0(a0)
  1784.     move.l #sounddata,$b0(a0)
  1785.     move.l #sounddata,$c0(a0)
  1786.     move.l #sounddata,$d0(a0)
  1787.     move.w #$10,$a4(a0)
  1788.     move.w #$10,$b4(a0)
  1789.     move.w #$10,$c4(a0)
  1790.     move.w #$10,$d4(a0)
  1791.     move.w #$3f,volume(a2)
  1792.     move.w #$800f,$96(a0)
  1793.     rts
  1794.  
  1795. init_error_sound
  1796.     
  1797.     move.w #$c00,$a6(a0)
  1798.     move.w #$c00,$b6(a0)
  1799.     move.w #$c00,$c6(a0)
  1800.     move.w #$c00,$d6(a0)
  1801.     bra sound
  1802.  
  1803. getdiskname
  1804.  
  1805.     clr.w total_error(a2)
  1806.     move.l #namereq,a6
  1807.     bsr showmessage
  1808.     clr.w charnumber(a2)
  1809.     move.l #diskname,a4
  1810.     moveq #30,d7
  1811. cdnlp    clr.b (a4)+
  1812.     dbf d7,cdnlp
  1813.  
  1814.     move.l #screen+(175*176)+3,a4
  1815. nxtchr    moveq #95,d0        ;print cursor
  1816.     clr.w d1
  1817.     move.b charnumber+1(a2),d1
  1818.     addq.b #5,d1
  1819.     bsr printchar
  1820.  
  1821. keyup    btst #7,keypressed(a2)
  1822.     bne.s keyup    
  1823.     clr.w d0
  1824.     move.b keypressed(a2),d0
  1825.     move.b d0,oldkey(a2)
  1826.  
  1827.     cmpi.b #$45,d0
  1828.     beq cancel_frmt
  1829.     cmpi.b #$44,d0        ;return?
  1830.     beq gotname
  1831.     cmpi.b #$41,d0        ;delete?
  1832.     bne.s notdel
  1833.     
  1834.     move.l #diskname+1,a3
  1835.     move.w charnumber(a2),d1
  1836.     subq.b #1,d1
  1837.     bmi samekey        ;cannot delete if pos 0    
  1838.     clr.b $00(a3,d1.w)
  1839.     moveq #0,d0
  1840.     clr.w d1
  1841.     move.b charnumber+1(a2),d1    ;erase cursor character
  1842.     addq.w #5,d1
  1843.     bsr printchar
  1844.     subq.w #1,charnumber(a2)
  1845.     bra samekey
  1846.  
  1847. notdel    cmpi.w #30,charnumber(a2)
  1848.     beq samekey
  1849.  
  1850.     move.l #keycdconv,a6
  1851.     tst.w shift_on(a2)
  1852.     beq.s noshift
  1853.     add.w #$80,a6
  1854. noshift    move.b $00(a6,d0.w),d0    ;ascii character
  1855.     beq samekey
  1856.  
  1857.     move.l #diskname+1,a3
  1858.     move.w charnumber(a2),d1
  1859.     move.b d0,$00(a3,d1.w)
  1860.     sub.b #32,d0    
  1861.     clr.w d1
  1862.     move.b charnumber+1(a2),d1
  1863.     addq.b #5,d1
  1864.     bsr printchar
  1865.     addq.w #1,charnumber(a2)
  1866.     
  1867. samekey    move.b keypressed(a2),d0
  1868.     cmp.b oldkey(a2),d0
  1869.     beq.s samekey
  1870.     bra nxtchr
  1871.  
  1872. gotname    move.w charnumber(a2),d0
  1873.     beq.s defname
  1874.     move.b d0,diskname
  1875.     bra namedone
  1876.  
  1877. defname    move.l #blankname,a3
  1878.     move.l #diskname,a4
  1879.     moveq #30,d7
  1880. cbnlp    move.b (a3)+,(a4)+
  1881.     dbf d7,cbnlp
  1882.     
  1883. namedone    move.l #rootsect,a5        ;recalculate root block
  1884.     clr.l $14(a5)        ;checksum
  1885.     moveq #0,d6
  1886.     moveq #$7f,d7
  1887. redocslp    add.l (a5)+,d6
  1888.     dbf d7,redocslp
  1889.     neg.l d6
  1890.     move.l d6,rootsect+$14
  1891.     clr.w trackmade(a2)
  1892.     rts
  1893.  
  1894. cancel_frmt
  1895.  
  1896.     move.w #$ffff,total_error(a2)
  1897.     move.w #1,dont_check(a2)
  1898.     rts
  1899.  
  1900. ***********************
  1901. * Format support code *
  1902. ***********************
  1903.  
  1904. * This code will create a MFM track in the format_buffer for the
  1905. * track and side specified in variable offsets TRACK and SIDE_SEL
  1906.  
  1907. Create_track
  1908.  
  1909.     tst.w track(a2)        ;make boot trackside?
  1910.     bne.s not_bt
  1911.     tst.w side_sel(a2)
  1912.     beq.s not_bt
  1913.     bsr make_boot_track
  1914.     bra track_created
  1915.  
  1916. not_bt    cmpi.w #40,track(a2)    ;make root trackside?
  1917.     bne.s not_rt
  1918.     tst.w side_sel(a2)
  1919.     beq.s not_rt
  1920.     bsr make_root_track
  1921.     bra track_created
  1922. not_rt
  1923.     tst.w trackmade(a2)        ;normal track in buffer already?
  1924.     bne.s track_created
  1925.     bsr make_normal_track
  1926.  
  1927. track_created
  1928.     
  1929.     move.w #$ff00,d0        ;make top word of header
  1930.     move.b track+1(a2),d0    ;byte.
  1931.     lsl.b #1,d0
  1932.     or.b side_sel+1(a2),d0
  1933.     eori.b #1,d0
  1934.     swap d0
  1935.  
  1936.     move.l #format_buffer+$200,a4    ;now fill in unclocked HEADER DATA
  1937.     moveq #0,d7        ;in each sector.
  1938. nextsect    
  1939.     move.b d7,d0    
  1940.     lsl.w #8,d0        ;sector number
  1941.     move.b #$b,d0
  1942.     sub.b d7,d0        ;blocks before gap
  1943.     
  1944.     move.l d0,d1
  1945.     move.l d0,d2
  1946.     andi.l #$aaaaaaaa,d1
  1947.     andi.l #$55555555,d2
  1948.     lsr.l #1,d1
  1949.     move.l d1,$8(a4)        ;put in unclocked header longwords
  1950.     move.l d2,$c(a4)        
  1951.     eor.l d1,d2        ;header checksum longword.
  1952.             
  1953.     move.l d2,d1
  1954.     andi.l #$aaaaaaaa,d1
  1955.     andi.l #$55555555,d2
  1956.     lsr.l #1,d1
  1957.     move.l d1,$30(a4)        ;put in unclocked header checksum
  1958.     move.l d2,$34(a4)        ;longwords.
  1959.  
  1960.     lea $8(a4),a3        ;now fill in the missing clocks
  1961.     moveq #1,d4        ;prev data bit = 1 (from sync)
  1962.     moveq #3,d6        ;longwords to do (part 1)
  1963.     bsr fill_clocks
  1964.  
  1965.     lea $30(a4),a3        
  1966.     moveq #0,d4        ;prev data bit = 0 (from padding)
  1967.     moveq #5,d6        ;longwords to do (part 2)
  1968.     bsr fill_clocks
  1969.  
  1970.     add.w #$440,a4
  1971.     addq.w #1,d7
  1972.     cmpi.w #$b,d7        ;end sector loop?
  1973.     bne.s nextsect
  1974.     move.l #format_buffer,write_addr(a2)
  1975.     rts
  1976.  
  1977.  
  1978. Make_boot_track
  1979.     
  1980.     move.l #format_buffer,a6
  1981.     bsr makegap
  1982.     move.l #bootsect,a5
  1983.     bsr make_mfm_sector
  1984.     add.w #$440,a6
  1985.     move.l #bootsect+$200,a5
  1986.     bsr make_mfm_sector    
  1987.     add.w #$440,a6
  1988.     moveq #8,d7
  1989. othsect1    move.l #nullsect,a5
  1990.     bsr make_mfm_sector
  1991.     add.w #$440,a6
  1992.     dbf d7,othsect1    
  1993.     bsr makegap
  1994.     clr.w trackmade(a2)
  1995.     rts
  1996.  
  1997. Make_normal_track
  1998.  
  1999.     move.l #format_buffer,a6
  2000.     bsr makegap
  2001.     moveq #$a,d7
  2002. othsect2    move.l #nullsect,a5
  2003.     bsr make_mfm_sector
  2004.     add.w #$440,a6
  2005.     dbf d7,othsect2
  2006.     bsr makegap
  2007.     move.w #1,trackmade(a2)
  2008.     rts
  2009.  
  2010. Make_root_track
  2011.  
  2012.     move.l #format_buffer,a6
  2013.     bsr makegap
  2014.     move.l #rootsect,a5
  2015.     bsr make_mfm_sector
  2016.     add.w #$440,a6
  2017.     move.l #rootsect+$200,a5
  2018.     bsr make_mfm_sector    
  2019.     add.w #$440,a6
  2020.     moveq #8,d7
  2021. othsect3    move.l #nullsect,a5
  2022.     bsr make_mfm_sector
  2023.     add.w #$440,a6
  2024.     dbf d7,othsect3
  2025.     bsr makegap
  2026.     clr.w trackmade(a2)
  2027.     rts
  2028.  
  2029. makegap    move.w #$ff,d7
  2030. gaplp    move.w #$aaaa,(a6)+
  2031.     dbf d7,gaplp
  2032.     rts
  2033.  
  2034.  
  2035. * Make Amiga MFM sector from 512 byte data block.
  2036.  
  2037. * Set A5 to Address of Data block to convert.
  2038. * Set A6 to Address to place MFM sector.
  2039.  
  2040. Make_MFM_Sector
  2041.  
  2042.     movem.l a0-a6/d0-d7,-(a7)
  2043.     moveq #0,d6        ;prev data bit
  2044.  
  2045. maketrack_lp    
  2046.  
  2047.     btst #0,-$1(a6)
  2048.     beq.s prev0
  2049.     move.w #$2aaa,(a6)
  2050.     bra.s prev1
  2051.  
  2052. prev0    move.w #$aaaa,(a6)        ;padding
  2053. prev1    move.w #$aaaa,$2(a6)    
  2054.     move.l #$44894489,$4(a6)    ;sync words
  2055.     
  2056.     move.l #$aaaaaaaa,$10(a6)    ;more padding
  2057.     move.l #$aaaaaaaa,$14(a6)
  2058.     move.l #$aaaaaaaa,$18(a6)    
  2059.     move.l #$aaaaaaaa,$1c(a6)
  2060.     move.l #$aaaaaaaa,$20(a6)    
  2061.     move.l #$aaaaaaaa,$24(a6)
  2062.     move.l #$aaaaaaaa,$28(a6)
  2063.     move.l #$aaaaaaaa,$2c(a6)
  2064.     
  2065. * Separate odd / even bits for this data block *
  2066.  
  2067.     moveq #0,d0
  2068.     lea $40(a6),a3        ;store start of block address
  2069.     moveq #$7f,d4        ;split original block into odd/even
  2070. splitloop    move.l (a5)+,d7        ;all clock bits low.
  2071.     move.l d7,d5
  2072.     move.l d7,d6
  2073.     andi.l #$aaaaaaaa,d5    ;odd bits
  2074.     andi.l #$55555555,d6    ;even bits
  2075.     lsr.l #1,d5
  2076.     eor.l d5,d0        ;update data checksum
  2077.     eor.l d6,d0        ;update data checksum
  2078.     move.l d5,(a3)
  2079.     move.l d6,$200(a3)
  2080.     addq.w #4,a3
  2081.     dbf d4,splitloop
  2082.  
  2083.     move.l d0,d5        ;put in unclocked data checksum
  2084.     move.l d0,d6
  2085.     andi.l #$aaaaaaaa,d5    
  2086.     andi.l #$55555555,d6    
  2087.     lsr.l #1,d5
  2088.     move.l d5,$38(a6)
  2089.     move.l d6,$3c(a6)
  2090.     move.l d6,d4        ;previous longword
  2091.  
  2092. * Fill in the data block clocks only *
  2093.  
  2094.     move.w #$ff,d6        ;longwords to do
  2095.     lea $40(a6),a3
  2096.     bsr fill_clocks
  2097.     movem.l (a7)+,a0-a6/d0-d7
  2098.     rts
  2099.  
  2100. fill_clocks
  2101.  
  2102.     movem.l a3/d2-d4/d7,-(a7)
  2103. lw_loop    move.l (a3),d7        ;get unclocked mfm longword
  2104.     andi.l #$55555555,d7    ;remove any clocks just in case
  2105.  
  2106.     moveq #30,d2        ;bit count
  2107. conv_lp    btst d2,d7
  2108.     bne.s notzero
  2109.     cmpi.w #30,d2        ;first bit on right
  2110.     bne.s not1st
  2111.     
  2112.     btst #0,d4        ;check last bit for previous
  2113.     bne notzero        ;longword
  2114.     move.l d2,d3
  2115.     addq.w #1,d3
  2116.     bra zero
  2117.     
  2118. not1st    move.l d2,d3        ;check bit before
  2119.     addq.w #2,d3
  2120.     btst d3,d7
  2121.     bne.s notzero
  2122.     subq.w #1,d3
  2123. zero    bset d3,d7        ;set this clock bit.
  2124.  
  2125. notzero    subq.w #2,d2        ;next bit in longword
  2126.     bpl.s conv_lp
  2127.  
  2128.     move.l d7,d4
  2129.     move.l d4,(a3)+        ;replace the unclckd mfm lw 
  2130.  
  2131.     dbf d6,lw_loop        ;next longword to do.
  2132. end
  2133.     movem.l (a7)+,a3/d2-d4/d7
  2134.     rts
  2135.  
  2136. *****************************************************************************
  2137.     
  2138.     section kcopydata,data
  2139.  
  2140. vars    dcb.w $40,$0
  2141.  
  2142. pointerx       equ $0
  2143. pointery       equ $2
  2144. oldmousex    equ $4
  2145. oldmousey    equ $5
  2146. button_latch equ $6
  2147. clicked_box  equ $8
  2148. destination  equ $a
  2149. check_mode   equ $c
  2150. recopy_mode  equ $e
  2151. starttrack   equ $10
  2152. endtrack     equ $12
  2153. irq_occured  equ $14
  2154. disk_error   equ $16
  2155. track        equ $18
  2156. firstsync    equ $1a
  2157. re_read      equ $1e
  2158. write_addr   equ $20
  2159. volume       equ $24
  2160. not_used     equ $26
  2161. recopycount  equ $28
  2162. sourcestatus equ $2a
  2163. use_sides    equ $2c
  2164. side_sel     equ $2e
  2165. keypressed   equ $30
  2166. charnumber   equ $32
  2167. oldkey       equ $34
  2168. trackmade    equ $36
  2169. total_error  equ $38
  2170. mouse_lock   equ $3a
  2171. rmb_latch    equ $3c
  2172. dont_check   equ $3e
  2173. adjrng_mode  equ $40
  2174. track_bcd       equ $42
  2175.  
  2176. orig_inten     equ $44
  2177. orig_intreq    equ $46
  2178. orig_lev2        equ $48
  2179. orig_lev3        equ $4c
  2180. orig_usp        equ $50
  2181. orig_a7        equ $54
  2182. orig_dmacon    equ $58
  2183. orig_df0        equ $5a
  2184. orig_df1        equ $5c
  2185. orig_cr1        equ $5e
  2186. orig_tl1        equ $5f
  2187. orig_th1        equ $60
  2188. orig_cr2        equ $61
  2189. orig_tl2        equ $62
  2190. orig_th2        equ $63
  2191. orig_bfd100    equ $64
  2192. orig_bfe001    equ $65
  2193. orig_adkcon    equ $66
  2194. orig_copper    equ $68
  2195. shift_on        equ $6c
  2196. orig_zero        equ $6e
  2197.  
  2198. box_areas    dc.b 8,6,10,13        ;1-copy (y,x to y,x)
  2199.     dc.b 11,6,13,13        ;2-check
  2200.     dc.b 15,18,17,24        ;3-stop
  2201.     dc.b 11,30,13,39        ;4-format
  2202.     dc.b 11,15,13,28        ;5-dest
  2203.     dc.b 4,16,6,42        ;6-check sys/recopy
  2204.     dc.b 15,3,17,16        ;7-sides
  2205.     dc.b 15,26,17,34        ;8-default
  2206.     dc.b 8,15,10,28        ;9-source
  2207.     dc.b 15,36,17,43        ;a-quit to dos
  2208.     dc.b 8,30,10,39        ;b-fetch disk name
  2209.     dc.b 0,0,0,0        ;c-not used
  2210.     dc.b 0,0,0,0        ;d-not used
  2211.     dc.b 0,0,0,0        ;e-not used
  2212.  
  2213. bootsect    incbin kc2.5bootblocks
  2214.  
  2215. rootsect    incbin kc2.5rootblocks
  2216.  
  2217. nullsect    incbin kc2.5blankblock
  2218.  
  2219. diskname  equ rootsect+432
  2220.  
  2221. nullmsg   dc.b "                                    ",0
  2222. welcome   dc.b "WELCOME TO KWIKCOPY 2.5 BY PHIL!94",0
  2223. taskdone0    dc.b "TASK COMPLETE: ERRORS!!",0
  2224. taskdone1    dc.b "TASK COMPLETE: DISK OK!",0
  2225. taskdone2    dc.b "TASK COMPLETE!",0
  2226. formting0    dc.b "FORMATTING DISK IN DF0:",0
  2227. formting1    dc.b "FORMATTING DISK IN DF1:",0
  2228. checking0    dc.b "CHECKING DISK IN DF0:",0 
  2229. checking1    dc.b "CHECKING DISK IN DF1:",0
  2230. copying0    dc.b "COPYING DF0: TO DF1:",0
  2231. copying1    dc.b "COPYING DF1: TO DF0:",0
  2232. terminate dc.b "TASK TERMINATED!",0
  2233. no_disk0  dc.b "NO DISK IN DF0!",0
  2234. no_disk1  dc.b "NO DISK IN DF1!",0
  2235. writepro  dc.b "DISK IS WRITE PROTECTED!",0
  2236. namereq   dc.b "NAME:",0
  2237. nodf1     dc.b "DF1: NOT AVAILABLE!!",0
  2238. no_name    dc.b "DISK NAME IS INVALID!",0
  2239. goodbye    dc.b "BYE BYE!",0
  2240.  
  2241. sidestext    dc.b "UPPER",$a
  2242.     dc.b "LOWER",$a
  2243.     dc.b "BOTH ",$a
  2244.  
  2245. sourcetxt dc.b "DF0:",$a
  2246.     dc.b "DF1:",$a
  2247.  
  2248. checktxt  dc.b "OFF : NO CHECK! ",$a
  2249.     dc.b "DURING:0 RETRIES",$a
  2250.     dc.b "AFTER TASK      ",$a
  2251.  
  2252. retrytxt    dc.b "0",$a,"1",$a,"2",$a,"3",$a,"4",$a
  2253.     dc.b "5",$a,"6",$a,"7",$a,"8",$a,"9",$a
  2254.  
  2255.      even
  2256.  
  2257. gfxlib.txt dc.b "graphics.library",$0
  2258.  
  2259. errornos    incbin errornumbers.raw
  2260.  
  2261. blankname dc.b 22,"Kwikcopy2.5-Blank-Disk",0,0,0,0,0,0,0,0
  2262.  
  2263. asciiconv incbin 4planefontsasciiconvtable
  2264.  
  2265. keycdconv    incbin Keycode-ascii.table
  2266.  
  2267. charmap     incbin screencharmap
  2268.  
  2269. FOURplanefont incbin 4planecset.raw
  2270.  
  2271. ONEplanefont  incbin 1planecset.raw
  2272.  
  2273.      even
  2274.  
  2275. stack1    dcb.l $80,$0
  2276.  
  2277. stack2    dcb.l $80,$0
  2278.  
  2279. stack3    dc.l $0
  2280.  
  2281. decoded_rootblock dcb.l $80,$0
  2282.  
  2283. *****************************************************************************
  2284.  
  2285.     section chipstuff,data_c
  2286.  
  2287. copper1    dc.l $0101ff00,$01060000,$01fc0000
  2288. copper2    dc.l $0201ff00,$00e00000,$00e20000,$00e40000
  2289.     dc.l $00e60000,$00e80000,$00ea0000,$00ec0000
  2290.     dc.l $00ee0000,$01004200,$01020000,$0104003f
  2291.     dc.l $008e4480,$009003d0,$00920038,$009400d0
  2292.     dc.l $01080088,$010a0088,$01200000,$01220000
  2293.     dc.l $01240000,$01260000,$01280000,$012a0000
  2294.     dc.l $012c0000,$012e0000,$01300000,$01320000
  2295.     dc.l $01340000,$01360000,$01380000,$013a0000
  2296.     dc.l $013c0000,$013e0000,$01800000,$018203f1
  2297.     dc.l $01840f00,$01860820,$0188008f,$018a0639
  2298.     dc.l $018c0457,$018e08ab,$0190095e,$01920a6e
  2299.     dc.l $01940b8e,$01960cae,$01980dbf,$019a0edf
  2300.     dc.l $019c0eef,$019e0fff,$01a00000,$01a20fff
  2301.     dc.l $01a4000f,$01a60008,$01a80000,$01aa00f0
  2302.     dc.l $01ac00c0,$01ae0090,$01b00000,$01b20f00
  2303.     dc.l $01b40c00,$01b60900,$01b80000,$01ba0000
  2304.     dc.l $01bc0000,$01be0000
  2305.  
  2306.     dc.l $5a01ff00,$01080086,$010a0086,$01020077
  2307.     dc.l $5b01ff00,$008e4470,$009003d0,$00920030
  2308.     dc.l $009400d8,$01080084,$010a0084
  2309.  
  2310.     dc.l $7a01ff00,$0108ffd4,$010affd4
  2311.  
  2312.     dc.l $7e01ff00,$01080086,$010a0086
  2313.     dc.l $7f01ff00,$008e4480,$009003d0,$00920038
  2314.     dc.l $009400d0,$01020000,$01080088,$010a0088
  2315.  
  2316.     dc.l $fffffffe
  2317.  
  2318.  
  2319. pointersprite:
  2320.     dc.w    $70c0,$7f00
  2321.     dc.w    $0004,$FFFC
  2322.     dc.w    $7FFC,$800C
  2323.     dc.w    $4018,$BFF8
  2324.     dc.w    $4030,$BFF0
  2325.     dc.w    $4020,$BFE0
  2326.     dc.w    $4050,$BFB0
  2327.     dc.w    $4028,$BFD8
  2328.     dc.w    $4014,$BFEC
  2329.     dc.w    $400E,$BFFE
  2330.     dc.w    $481C,$BFFC
  2331.     dc.w    $5C38,$BFF8
  2332.     dc.w    $7670,$B7F0
  2333.     dc.w    $63E0,$E3E0
  2334.     dc.w    $C1C0,$C1C0
  2335.     dc.w    $0080,$0080
  2336.     dc.w    $0000,$0000
  2337.     dc.w    $0000,$0000
  2338.  
  2339. trackstartsprite:    
  2340.     dc.w    $5b3b,$7900
  2341.     dc.w    $7C7C,$0000
  2342.     dc.w    $C6C6,$0000
  2343.     dc.w    $C6C6,$0000
  2344.     dc.w    $C6C6,$0000
  2345.     dc.w    $C6C6,$0000
  2346.     dc.w    $7C7C,$0000
  2347.     dc.w    $0000,$0000
  2348.     dc.w    $0380,$0080
  2349.     dc.w    $0280,$0180
  2350.     dc.w    $0280,$0180
  2351.     dc.w    $0280,$0180
  2352.     dc.w    $0280,$0180
  2353.     dc.w    $0280,$0180
  2354.     dc.w    $0280,$0180
  2355.     dc.w    $0280,$0180
  2356.     dc.w    $0280,$0180
  2357.     dc.w    $0280,$0180
  2358.     dc.w    $0280,$0180
  2359.     dc.w    $0280,$0180
  2360.     dc.w    $0280,$0180
  2361.     dc.w    $0280,$0180
  2362.     dc.w    $0280,$0180
  2363.     dc.w    $0280,$0180
  2364.     dc.w    $0280,$0180
  2365.     dc.w    $0290,$0180
  2366.     dc.w    $02E8,$0190
  2367.     dc.w    $0204,$01F8
  2368.     dc.w    $03E8,$03F8
  2369.     dc.w    $0010,$0010
  2370.     dc.w    $0000,$0000
  2371.     dc.w    $0000,$0000
  2372.  
  2373. trackendsprite:
  2374.  
  2375.     dc.w    $62dd,$8001
  2376.     dc.w    $0800,$0000
  2377.     dc.w    $17C0,$0840
  2378.     dc.w    $2040,$1FC0
  2379.     dc.w    $1740,$1EC0
  2380.     dc.w    $0940,$08C0
  2381.     dc.w    $0140,$00C0
  2382.     dc.w    $0140,$00C0
  2383.     dc.w    $0140,$00C0
  2384.     dc.w    $0140,$00C0
  2385.     dc.w    $0140,$00C0
  2386.     dc.w    $0140,$00C0
  2387.     dc.w    $0140,$00C0
  2388.     dc.w    $0140,$00C0
  2389.     dc.w    $0140,$00C0
  2390.     dc.w    $0140,$00C0
  2391.     dc.w    $0140,$00C0
  2392.     dc.w    $0140,$00C0
  2393.     dc.w    $0140,$00C0
  2394.     dc.w    $0140,$00C0
  2395.     dc.w    $0140,$00C0
  2396.     dc.w    $0140,$00C0
  2397.     dc.w    $01C0,$01C0
  2398.     dc.w    $0000,$0000
  2399.     dc.w    $7C7C,$0000
  2400.     dc.w    $C6C6,$0000
  2401.     dc.w    $C6C6,$0000
  2402.     dc.w    $C6C6,$0000
  2403.     dc.w    $C6C6,$0000
  2404.     dc.w    $7C7C,$0000
  2405.     dc.w    $0000,$0000
  2406.     dc.w    $0000,$0000
  2407.  
  2408. checklong dc.l $00000000
  2409.  
  2410. padding    dc.l $0,$0,$0,$0,$0,$0,$0,$0
  2411.  
  2412. mfm_buffer 
  2413.     dcb.l $1c00,$0
  2414.  
  2415. format_buffer 
  2416.  
  2417.     dcb.l $d00,$0
  2418.  
  2419. sounddata    dc.l $7f7f7f7f,$7f7f7f7f,$7f7f7f7f,$7f7f7f7f
  2420.     dc.l $80808080,$80808080,$80808080,$80808080
  2421.  
  2422. screen    incbin Kwikcopylogo2.raw
  2423.     
  2424.     dcb.l 44*176,$0
  2425.  
  2426. *****************************************************************************
  2427.  
  2428.